using System;
using System.Collections.Generic;
using System.Text;
using Zsa.Emulation.Memory;
using System.IO;

namespace Zsa.Emulation.Mappers
{
    /// <summary>
    /// Mapper for games that dont use a mapper.
    /// </summary>
    public class DefaultMapper : Mapper
    {


        #region Constructor
        /// <summary>
        /// Initializes a new instance of the <see cref="T:DefaultMapper"/> class.
        /// </summary>
        public DefaultMapper()
            : base ("None","Game does not use a mapper.",MapperTypeNumber.None)
        {
        }
        #endregion Constructor

        //#region Methods
        ///// <summary>
        ///// Called when [init].
        ///// </summary>
        //public override void OnInit()
        //{
        //    int _StreamSize = (int)GameCart.CartridgeStream.Length;

        //    byte[] _Bytes = new byte[_StreamSize];
        //    GameCart.CartridgeStream.Seek(0, SeekOrigin.Begin);
        //    GameCart.CartridgeStream.Read(_Bytes, 0, _StreamSize);
        //    _MapperStream = new MemoryStream(_Bytes, false);
            
                
        //    if (GameCart.FileInfo.PrgRomBankCount == 1 || GameCart.FileInfo.PrgRomBankCount == 2)
        //    {
        //        // Create the first memory bank.
        //        _PrgRomOne = new MemoryBank(
        //            NesMemoryConstants.PrgRomBankByteSize,
        //            NesMemoryConstants.PrgRomStart,
        //            //GameCart.CartridgeStream,
        //            _MapperStream,
        //            GameCart.FileInfo.GetOffset(RomBankType.ProgramRom, 0),
        //            true
        //            );
        //        // Create the second memory bank.
        //        _PrgRomTwo = new MemoryBank(
        //            NesMemoryConstants.PrgRomBankByteSize,
        //            NesMemoryConstants.PrgRomBankTwoStart,
        //            //GameCart.CartridgeStream,
        //            _MapperStream,
        //            GameCart.FileInfo.GetOffset(RomBankType.ProgramRom, GameCart.FileInfo.PrgRomBankCount == 2 ? 1 : 0),
        //            true
        //            );

        //        // Create the chr rom cart.  this might be writable for some carts??  Might not have??
        //        int _Offset = GameCart.FileInfo.GetOffset(RomBankType.VideoRom, 0);
        //        _ChrRomOne = new MemoryBank(
        //            0x1000,
        //            0,
        //            _MapperStream,
        //            _Offset,
        //            false
        //        );
        //        _ChrRomTwo = new MemoryBank(
        //            0x1000,
        //            0x1000,
        //            _MapperStream,
        //            _Offset+0x1000,
        //            false
        //        );
        //    }
        //    else
        //    {
        //        throw new NotImplementedException();
        //    }
        //}
        //#endregion Methods


        internal override bool OnBankWrite(Zsa.Emulation.Cartridge.RomBankType romBank, ushort address, byte value)
        {
            if (romBank == Zsa.Emulation.Cartridge.RomBankType.ProgramRom)
            {
                return true;
            }
            return false;
        }
    }
}
